﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BLL;
using IFactory;
public partial class UserPlanWeek_UserWeekPlanModify : System.Web.UI.Page
{
    Authentication dllAuthentication = new Authentication();

    UserPlanWeek dllUserPlanWeek = new UserPlanWeek();
    protected void Page_Load(object sender, EventArgs e)
    {
        dllAuthentication.isLogin();
        if (!IsPostBack)
        {
            bind();
        }
    }

    /// <summary>
    /// 绑定
    /// </summary>
    /// <author>grokyao</author>
    /// <date>2009-3-6</date>
    void bind()
    {
        object[] _value = new object[1];
        _value[0] = Utility.HttpHelp.getParamsInt("Id");
        DataTable _weekPlan = dllUserPlanWeek.get(UserPlanWeek.field.WeekPlanId.ToString(), _value);
        if (_weekPlan.Rows.Count > 0)
        {
            #region 去除标记
            _weekPlan.Rows[0]["CompleteTime"] = _weekPlan.Rows[0]["CompleteTime"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["CompleteTime"] = _weekPlan.Rows[0]["CompleteTime"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["CompleteTime"] = _weekPlan.Rows[0]["CompleteTime"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["StartTime"] = _weekPlan.Rows[0]["StartTime"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["StartTime"] = _weekPlan.Rows[0]["StartTime"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["StartTime"] = _weekPlan.Rows[0]["StartTime"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["MasterPeople"] = _weekPlan.Rows[0]["MasterPeople"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["MasterPeople"] = _weekPlan.Rows[0]["MasterPeople"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["MasterPeople"] = _weekPlan.Rows[0]["MasterPeople"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["MasterDepartment"] = _weekPlan.Rows[0]["MasterDepartment"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["MasterDepartment"] = _weekPlan.Rows[0]["MasterDepartment"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["MasterDepartment"] = _weekPlan.Rows[0]["MasterDepartment"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["WeekPlanSortId"] = _weekPlan.Rows[0]["WeekPlanSortId"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["WeekPlanSortId"] = _weekPlan.Rows[0]["WeekPlanSortId"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["WeekPlanSortId"] = _weekPlan.Rows[0]["WeekPlanSortId"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["Remart"] = _weekPlan.Rows[0]["Remart"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["Remart"] = _weekPlan.Rows[0]["Remart"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["Remart"] = _weekPlan.Rows[0]["Remart"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["SlaveDepartment"] = _weekPlan.Rows[0]["SlaveDepartment"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["SlaveDepartment"] = _weekPlan.Rows[0]["SlaveDepartment"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["SlaveDepartment"] = _weekPlan.Rows[0]["SlaveDepartment"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["SlaveDepartmentDuty"] = _weekPlan.Rows[0]["SlaveDepartmentDuty"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["SlaveDepartmentDuty"] = _weekPlan.Rows[0]["SlaveDepartmentDuty"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["SlaveDepartmentDuty"] = _weekPlan.Rows[0]["SlaveDepartmentDuty"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["EvaluatePeople"] = _weekPlan.Rows[0]["EvaluatePeople"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["EvaluatePeople"] = _weekPlan.Rows[0]["EvaluatePeople"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["EvaluatePeople"] = _weekPlan.Rows[0]["EvaluatePeople"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["WorkItem"] = _weekPlan.Rows[0]["WorkItem"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["WorkItem"] = _weekPlan.Rows[0]["WorkItem"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["WorkItem"] = _weekPlan.Rows[0]["WorkItem"].ToString().Replace("amp;", "");

            _weekPlan.Rows[0]["PlanStep"] = _weekPlan.Rows[0]["PlanStep"].ToString().Replace("&", "");
            _weekPlan.Rows[0]["PlanStep"] = _weekPlan.Rows[0]["PlanStep"].ToString().Replace("nbsp;", "");
            _weekPlan.Rows[0]["PlanStep"] = _weekPlan.Rows[0]["PlanStep"].ToString().Replace("amp;", "");

            #endregion


            this.txtCompleteTime.Text = Convert.ToDateTime(_weekPlan.Rows[0]["CompleteTime"]).ToShortDateString();
            this.txtStartTime.Text = Convert.ToDateTime(_weekPlan.Rows[0]["StartTime"]).ToShortDateString();
            //this.txtCompleteTime.Text = this.txtCompleteTime.Text.Substring(0, 10);
            //this.txtStartTime.Text = this.txtStartTime.Text.Substring(0, 10);
            this.txtMasterPeople.Value = _weekPlan.Rows[0]["MasterPeople"].ToString();
            this.txtMasterDepartment.Value = _weekPlan.Rows[0]["MasterDepartment"].ToString();
            this.txtWeekPlanSortId.Value = _weekPlan.Rows[0]["WeekPlanSortId"].ToString();
            this.txtCheckNote.Text = _weekPlan.Rows[0]["Remart"].ToString();
            this.txtSlaveDepartment.Value = _weekPlan.Rows[0]["SlaveDepartment"].ToString();
            this.txtSlaveDepartmentDuty.Text = _weekPlan.Rows[0]["SlaveDepartmentDuty"].ToString();
            this.txtEvaluatePeople.Value = _weekPlan.Rows[0]["EvaluatePeople"].ToString();
            this.txtWorkItem.Text = _weekPlan.Rows[0]["WorkItem"].ToString();
            this.txtPlanStep.Text = _weekPlan.Rows[0]["PlanStep"].ToString();
            this.txtRemark.Text = _weekPlan.Rows[0]["Remart"].ToString();
            this.txtCheckNote.Text = _weekPlan.Rows[0]["CheckNote"].ToString();
            this.txtVerifyPeopleOpinion.Text = _weekPlan.Rows[0]["VerifyPeopleOpinion"].ToString();
            //如果从员工月计划分解而来，则存在MonthPlanId
            this.MonthPlanId.Value = _weekPlan.Rows[0]["MonthPlanId"].ToString();
        }
    }
    /// <summary>
    /// 判断控件值是否为空
    /// </summary>
    /// <returns>空返回0，有值返回1</returns>
    /// <author>gzz</author>
    /// <date>2009-3-19 </date>
    int isNull()
    {
        #region 验证是否为空
        if (this.txtWeekPlanSortId.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtCompleteTime.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtMasterPeople.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtWorkItem.Text.Length == 0)
        {
            return 0;
        }
        if (this.txtSlaveDepartment.Value.Length == 0)
        {
            return 0;
        }
        if (this.txtSlaveDepartmentDuty.Text.Length < 18 && this.txtSlaveDepartment.Value != "独立完成")
        {
            return 0;
        }
        //if (this.txtStartTime.Text.Length == 0)
        //{
        //    return 0;
        //}
        if (this.txtEvaluatePeople.Value.Length == 0)
        {
            return 0;
        }
        return 1;
        #endregion
    }

    /// <summary>
    /// 时间验证
    /// </summary>
    bool verifyDate()
    {
        #region 必要验证判断
        ////判断完成时间是否大于起始时间

        //DateTime _startTime = Convert.ToDateTime(this.txtStartTime.Text.Trim());
        //DateTime _endTime = Convert.ToDateTime(this.txtCompleteTime.Text.Trim());
        //if (!dllAuthentication.IsEndTimeGreaterThanStartTime(_startTime, _endTime))
        //{
        //    Utility.HttpHelp.alert("完成时间需要大于起始时间", Page);
        //    return false;
        //}


        return true;
        #endregion
    }
    /// <summary>
    /// 修改事件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    /// <author>grokyao</author>
    /// <date></date>
    protected void btnModify_Click(object sender, EventArgs e)
    {
        int _isnull = isNull();
        if (_isnull == 0)
        {
            Utility.HttpHelp.alert("请输入完整", Page);
            return;
        }
        else
        {
            if (Convert.ToInt32(this.txtWeekPlanSortId.Value) == 0)
            {
                Utility.HttpHelp.alert("计划编号只能从1开始！", Page);
                return;
            }
            if (!verifyDate())
            {
                return;
            }
            if (this.txtMasterPeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("责任人不可为多人！", Page);
                return;
            }
            if (this.txtEvaluatePeople.Value.Contains(","))
            {
                Utility.HttpHelp.alert("评估人不可为多人！", Page);
                return;
            }
            object[] _value = new object[13];
            _value[0] = Convert.ToDateTime(this.txtCompleteTime.Text);
            _value[1] = this.txtMasterPeople.Value;
            _value[2] = this.txtMasterDepartment.Value;
            _value[3] = Convert.ToInt32(this.txtWeekPlanSortId.Value);
            _value[4] = this.txtCheckNote.Text;
            _value[5] = this.txtSlaveDepartment.Value;
            _value[6] = this.txtSlaveDepartmentDuty.Text;
            _value[7] = this.txtEvaluatePeople.Value;
            _value[8] = this.txtWorkItem.Text;
            _value[9] = Utility.HttpHelp.getParamsInt("Id");
            _value[10] = this.txtPlanStep.Text;
            _value[11] = this.txtVerifyPeopleOpinion.Text;
            _value[12] = this.txtRemark.Text;
            int result = dllUserPlanWeek.editUserWeekPlanByWeekPlanIdForAdmin(_value);
            if (result == 0)
            {
                Utility.HttpHelp.alert("修改员工周计划未成功，请重试！", Page);
            }
            else
            {
                int WeekDate = Utility.HttpHelp.getParamsInt("WeekDate");
                string User = Utility.HttpHelp.getParamsString("User");
                string url = string.Empty;
                if (Request.QueryString["url"] != null)
                {
                    url = Request.QueryString["url"].ToString();
                }
                if (url.Length > 0)
                {
                    Utility.HttpHelp.closeWindow(url + "?WeekDate=" + WeekDate + "&depart=" + Utility.HttpHelp.getParamsString("depart") + "&Year=" + Utility.HttpHelp.getParamsString("Year") + "&QuarterDate=" + Utility.HttpHelp.getParamsString("QuarterDate") + "&MonthDate=" + Utility.HttpHelp.getParamsString("MonthDate") + "&User=" + User, Page);
                }
                else
                {
                    Utility.HttpHelp.closeWindow("UserPlanWeekList.aspx?Id=" + WeekDate + "&depart=" + Utility.HttpHelp.getParamsString("depart") + "&Year=" + Utility.HttpHelp.getParamsString("Year") + "&QuarterDate=" + Utility.HttpHelp.getParamsString("QuarterDate") + "&MonthDate=" + Utility.HttpHelp.getParamsString("MonthDate") + "&User" + User, Page);
                }
            }
        }
    }
}